package indi.zhifa.study2025.oa.service.dep.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import indi.zhifa.engine.core.common.entity.web.ServiceException;
import indi.zhifa.study2025.oa.dao.gen.service.IGenPositionTagDbService;
import indi.zhifa.study2025.oa.dao.po.GenPositionTagEntity;
import indi.zhifa.study2025.oa.service.dep.IPositionTagService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@RequiredArgsConstructor
@Component
public class PositionTagServiceImpl implements IPositionTagService {

    final IGenPositionTagDbService mGenPositionTagDbService;

    @Override
    public GenPositionTagEntity create(GenPositionTagEntity genPositionTagEntity) {
        LambdaQueryWrapper<GenPositionTagEntity> queryWrapper = new LambdaQueryWrapper<GenPositionTagEntity>()
                .eq(GenPositionTagEntity::getCode, genPositionTagEntity.getCode());
        if(mGenPositionTagDbService.exists(queryWrapper)) {
            throw new ServiceException("已存在code为"+genPositionTagEntity.getCode()+"的positionTag");
        }
        if(!mGenPositionTagDbService.save(genPositionTagEntity)){
            throw new ServiceException("存储GenPositionTagEntity失败");
        }

        return genPositionTagEntity;
    }

    @Override
    public GenPositionTagEntity edit(Long pId, Object genPositionTagEntity) {
        GenPositionTagEntity rtn = mGenPositionTagDbService.updatePull(pId, genPositionTagEntity);
        return rtn;
    }

    @Override
    public GenPositionTagEntity delete(Long pId) {
        GenPositionTagEntity rtn = mGenPositionTagDbService.deleteById(pId);
        return rtn;
    }

    @Override
    public GenPositionTagEntity check(Long pId) {
        GenPositionTagEntity rtn = mGenPositionTagDbService.check(pId);
        return rtn;
    }

    @Override
    public GenPositionTagEntity checkMin(Long pId) {
        GenPositionTagEntity rtn = mGenPositionTagDbService.checkMin(pId);
        return rtn;
    }

    @Override
    public List<GenPositionTagEntity> list() {
        List<GenPositionTagEntity> rtn = mGenPositionTagDbService.list();
        return rtn;
    }
}
